import dropdown_forlist from "./dropdown_forlist";

let TEMPLATE = `
<el-container>
    <el-header style="text-align: right; font-size: 12px">
        <dropdown_forlist></dropdown_forlist>
    </el-header>
    <br>
    <el-container v-loading="isloading" element-loading-text="拼命加载中">
        <h1 v-if="mid_txt">{{mid_txt}}</h1>
        <el-row>
            <el-col v-for="(cardinfo, index) in cardlist" :key="index" :span="12">
                <el-card shadow="hover" style="width: 20rem;">
                    <div slot="header" class="clearfix">
                        <span>{{cardinfo.name}}</span>
                        <el-button style="float: right; padding: 3px 0" type="text" @click="down_file(cardinfo.filename)">下载</el-button>
                    </div>
                    <div>
                        <h4>{{cardinfo.ver}}</h4>
                    </div>
                    <div>
                        <h5>{{cardinfo.desc}}</h5>  
                    </div>
                </el-card>
            </el-col>
        </el-row>
    </el-container>
</el-container>
`;


export default {
    name: "list_tools",
    template: TEMPLATE,
    data: function () {
        let ret = {
            line_maxnum: "2",
            row_maxnum: "2",
            cardlist: [
            ],
            isloading: true,    
            mid_txt:undefined
        }
        return ret;
    },
  
    components: {
        "dropdown_forlist": dropdown_forlist
    },

    mounted: function () {
        axios.get("/api/devcli/get_pageinfo?ltype=tools").then(
            (resp) => {
                console.log("http resp get_pageinfo?ltype=tools:%s",resp.toString());
                let issuc = false;
                let ret;
                if (resp.data.hasOwnProperty("data")) {
                    if (resp.data["r"] == 0) {
                        issuc = true;
                        ret = resp.data["data"]
                    }
                }
                if (issuc) {
                    let info;
                    for (const idx in ret) {
                        info = ret[idx];
                        if (info.hasOwnProperty("uploadtime")) {
                            let date = new Date(info["uploadtime"] * 1000);
                            info["uploadtime"] = date.toLocaleDateString();
                        }
                    }    
                    this.cardlist = ret;
                }
                else{
                    this.mid_txt = resp.data["desc"]
                }
                this.isloading = false;
            }
        )
    },
    methods: {
        down_file: function (sdfile) {
            console.log("down file-->>%s", sdfile);
            let a = document.createElement("a");
            a.href = "/dltools/" + sdfile;
            a.download = "下载";
            console.log(a.href, "--_>>>a.href ");
            a.click();
        }
    },

}


